﻿/*******************************************************
 * 
 * 作者：胡庆访
 * 创建时间：20100326
 * 说明：当前工程所对应的模块类
 * 运行环境：.NET 3.5 SP1
 * 版本号：1.0.0
 * 
 * 历史记录：
 * 创建文件 胡庆访 20100326
 * 
*******************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using Avalon.Windows.Controls;
using AvalonDock;
using OpenExpressApp.MetaModel;
using OpenExpressApp.Template;
using OpenExpressApp.WPF;
using OpenExpressApp.WPF.SystemModule;
using System.ComponentModel.Composition;
using OpenExpressApp.Library;
using System.ComponentModel.Composition.Hosting;

namespace OpenExpressApp.Module.WPF.SystemModule
{
    /// <summary>
    /// 当前工程所对应的模块类。
    /// 详细功能，见Initailize方法。
    /// </summary>
    [Export(typeof(IModule))]
    public class WPFModule : AdaptCommandModule
    {
        [Import]
        private CompositionContainer _compositionContainer = null;

        /// <summary>
        /// 把ModuleListPad.xaml加入到region中。
        /// 
        /// 加入ComboDataGrid.xaml到Resource中
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            OpenApplication.CompositionContainer = _compositionContainer;
            //加入资源集：ComboDataGrid.xaml
            this.AddResouce("OpenExpressApp.Module.WPF;component/Resources/ComboDataGrid.xaml");
            this.AddResouce("OpenExpressApp.Module.WPF;component/Resources/Resource.xaml");

            ViewFactory.Instance = new WPFViewFactory();
        }

        /// <summary>
        /// 把指定的Resouce加入到应用程序中
        /// </summary>
        /// <param name="relativeUri"></param>
        private void AddResouce(string relativeUri)
        {
            var uri = new Uri(relativeUri, UriKind.Relative);
            var resouceDic = Application.LoadComponent(uri) as ResourceDictionary;
            Application.Current.Resources.MergedDictionaries.Insert(0, resouceDic);
        }
    }
}
